package cn.myjerry.io.others;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.util.Scanner;

/**
 * System三种状态
 * 	1、System.in	 输入流   键盘输入
 * 	2、System.out	输出流  输出到控制台
 * 	   System.err
 * 
 * ==> 重定向
 * setIn()
 * setOut()
 * setErr()
 * 
 * FileDescriptor.in
 * FileDescriptor.out
 * @author Jerry
 *
 */

public class SystemDemo01 {
	public static void main(String[] args) throws FileNotFoundException {
		//test01()
		//test02();
		// 重定向
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(new File("/Users/zpon/Desktop/test05.txt"))), true));
		System.out.println("a"); // 控制台 --> 文件
		System.out.println("adc");
		// 回控制台
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true));
		System.out.println("back...");
	}
	public static void test02() throws FileNotFoundException {
		InputStream is = System.in;
		is = new BufferedInputStream(new FileInputStream(new File("/Users/zpon/Desktop/test04.txt")));
		Scanner sc = new Scanner(is);
		System.out.println(sc.nextLine());
	}
	
	public static void test01() {
		System.out.println(111);
		System.err.println(111);
	}
}
